﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DTO;
using BUS;

public partial class ChiTietSanPham : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        lbthongbao.Visible = false;
        //if (IsPostBack)
        //    return;
        String ID = Request.QueryString["ID"];
        SanPhamDTO sanpham = SanPhamBUS.LaySanPhamTheoID(int.Parse(ID));
        HangSanXuatDTO hangsanxuat = HangSanXuatBUS.LayHangSanXuatTheoID(sanpham.MaHangSanXuat);

        TenSanPham.Text = sanpham.TenSanPham;
        ImageSanPham.ImageUrl = "~/Image/" + sanpham.HinhSanPham;
        
        GiaSanPham.Text = sanpham.GiaBanHienTai.ToString() + "  .VND";

        ChiTietLapTopDTO laptop = ChiTietLapTopBUS.LayChiTietLapTopTheoID(int.Parse(ID));
        ThongTinCPU.Text = laptop.ThongTinCPU;
        TocDoCPU.Text = laptop.TocDoCPU;
        KichThuocManHinh.Text = laptop.KichThuocManHinh;
        VGA.Text = laptop.VGA;
        DungLuongVGA.Text = laptop.DungLuongVGA;
        RAM.Text = laptop.RAM;
        DungLuongRAM.Text = laptop.DungLuongRAM;
        ThongTinHDD.Text = laptop.ThongTinHDD;
        DungLuongHDD.Text = laptop.DungLuongHDD;
        Pin.Text = laptop.Pin;
        ThongTinMainBoard.Text = laptop.ThongTinMainBoard;
        ThongTinLAN.Text = laptop.ThongTinLAN;
        ThongTinWifi.Text = laptop.ThongTinWifi;
        ThongTinHDH.Text = laptop.ThongTinHeDieuHanh;
        ThongTinBaoHanh.Text = laptop.ThongTinBaoHanh;
        TrongLuongMay.Text = laptop.TrongLuongMay;
        TrangChu.Text = hangsanxuat.URL.ToString();
        TrangChu.NavigateUrl = hangsanxuat.URL.ToString();


        List<GianHangDTO> listGianHang = new List<GianHangDTO>();

        List<SanPhamThuongDangBanTrenGianHangDTO> listspthuong = SanPhamThuongDangBanTrenGianHangBUS.LayDanhSachSanPhamThuongTheoMaSanPham(int.Parse(ID));
        foreach (SanPhamThuongDangBanTrenGianHangDTO spthuong in listspthuong)
        {
            if (BUS.GianHangBUS.LayGianHangTheoID(spthuong.MaGianHang).TinhTrang == true)
                listGianHang.Add(BUS.GianHangBUS.LayGianHangTheoID(spthuong.MaGianHang));
        }
        if (listGianHang.Count == 0)
        {
            lbthongbao.Visible = true;
        }
        CollectionPager2.PageSize = 9;
        CollectionPager2.DataSource = listGianHang;
        CollectionPager2.BindToControl = dtlGianHang;
        dtlGianHang.DataSource = CollectionPager2.DataSourcePaged;
    }  
}
